﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Common;

namespace Common
{
    public enum UnitActionType
    {
        AirUnit,
        WaterUnit,
        LandUnit,
    }

    /// <summary>
    /// 发出攻击事件句柄
    /// </summary>
    /// <param name="sender">攻击发出者</param>
    /// <param name="attack">使用攻击</param>
    public delegate void AttachHandler (object sender, IAttack attack);

    /// <summary>
    /// 击中目标事件句柄
    /// </summary>
    /// <param name="sender">攻击发出者</param>
    /// <param name="target">击中目标</param>
    /// <param name="attack">使用攻击</param>
    public delegate void HitHandler (object sender, int[] target, IAttack attack);

    public abstract class IAttack : ActionBase
    {
        public abstract event Action<IAttack> OnEnd;
    }

    public abstract class ISpellAttack : IAttack
    {
    }

    public interface IEnemy
    {
        /// <summary>
        /// 单位属性
        /// </summary>
        UnitActionType UnitType
        {
            get;
        }

        /// <summary>
        /// 资源名称
        /// </summary>
        string ObjectName
        {
            get;
        }

        /// <summary>
        /// 武器名
        /// </summary>
        string WeaponName
        {
            get;
        }

        /// <summary>
        /// 正常攻击
        /// </summary>
        IAttack CreateAttack (object root);

        /// <summary>
        /// 警戒距离
        /// </summary>
        Vector3 AlertDistance
        {
            get;
        }

        /// <summary>
        /// 撤退距离
        /// </summary>
        Vector3 WithdrawDistance
        {
            get;
        }

        /// <summary>
        /// 攻击距离
        /// </summary>
        Vector3 AttackDistance
        {
            get;
        }

        /// <summary>
        /// 正常移动速度
        /// </summary>
        Vector3 NormalSpeed
        {
            get;
        }

        int MaxHP
        {
            get;
        }

        int MaxMP
        {
            get;
        }

        int IdleTick
        {
            get;
        }

        ///// <summary>
        ///// IDLE动画名
        ///// </summary>
        //string Idle
        //{
        //    get;
        //}

        ///// <summary>
        ///// 跑步动画名
        ///// </summary>
        //string Run
        //{
        //    get;
        //}

        ///// <summary>
        ///// 停止当前攻击
        ///// </summary>
        //void StopAttack ();

        ///// <summary>
        ///// 准备发动攻击
        ///// </summary>
        //event AttachHandler BeforeRiseAttack;

        ///// <summary>
        ///// 已经发动完攻击
        ///// </summary>
        //event AttachHandler AfterRiseAttack;

        ///// <summary>
        ///// 被击中时触发事件
        ///// </summary>
        //event HitHandler OnHitted;

        ///// <summary>
        ///// 被击中致死时
        ///// </summary>
        //event HitHandler OnHitToDead;

        ///// <summary>
        ///// 利用默认方式进行物理攻击
        ///// </summary>
        //void WeaponAttack ();

        ///// <summary>
        ///// 利用默认方式进行魔法攻击
        ///// </summary>
        //void SpellAttack ();
    }

    public interface IBoss : IEnemy
    {
    }

    public class HitEventArgs : EventArgs
    {
        public int AttakerID;
        public int AttakeeID;
        public int DeltaHP;
        public int RemainHP;
        public int MaxHP;
    }

    public interface IEnemyManager
    {
        ///// <summary>
        ///// 场景正常加载之后，在适当位置加入小怪物
        ///// </summary>
        ///// <param name="initPosition">初始位置</param>
        ///// <param name="unit">单位</param>
        //void AddEnemy (Vector3 initPosition, IEnemy unit);

        ///// <summary>
        ///// 加入场景随机出现怪物
        ///// </summary>
        ///// <param name="unit"></param>
        //void AddEnemy (IEnemy unit);


        void InitRegion (GameObject region);

        ///// <summary>
        ///// 加入BOSS 
        ///// </summary>
        ///// <param name="boss"></param>
        //void AddBoss (IBoss boss);

        //event Action<HitEventArgs> OnHit;

        List<IUnit> AllMonsters
        {
            get;
        }
    }
}
